<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="t" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>  
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>User Form Page</title>
</head>
<script type="text/javascript">
	function doSubmit() {
		var f = document.forms[0];
		if (f.from_mode.value == 'goForm') {
			f.submit();
		}
	}
</script>
<body>
  <h2>User Form Page</h2>
  <form id="form1" method="post" action="updateUser" > 
  <input type="hidden" id="message" value="${message}"/>
  <input type="hidden" id="from_mode" value="${from_mode}"/>
  <table>
  	<tr>
  		<td align="right">ID:</td>
  		<td><input type="text" id="id" name="id" value= "${person.ID}" readonly/></td>
  	</tr>
  	<tr>
  		<td align="right">Name:</td>
  		<td><input type="text" id="name" name="name" value="${person.NAME}" readOnly/></td>
  	</tr>
  	<tr>
  		<td align="right">Age:</td>
  		<td><input type="text" id="age" name="age" value="${person.AGE}" readOnly/></td>
  	</tr>
  	<tr>
  		<td align="right">Sex:</td>
  		<td><input type="text" id="sex" name="sex" value="${person.SEX}" readOnly/></td>
  	</tr>
  	<tr>
  		<td align="right">City:</td>
  		<td><input type="text" id="city" name="city" value="${person.CITY}" readOnly/></td>
  	</tr>
  	
  </table> 
    <input type="button" value="Submit" onclick="doSubmit()"/>  
  </form>  

</body>
<script type="text/javascript">
	function onLoad() {
		
		var f = document.forms[0];
		var msg = f.message.value;
		//var from_mode = form1.from_mode.value;
		//alert(from_mode);
		if (f.id.value == '') {
			history.go(-1);
		}
		
		if (f.from_mode.value == 'goForm') {
			document.getElementById("name").readOnly = false;
			document.getElementById("age").readOnly = false;
			document.getElementById("sex").readOnly = false;
			document.getElementById("city").readOnly = false;
		}
		
		if (msg == 'success') {
			alert(msg);
		}
	}
    window.onload = onLoad();
</script>
	<a href="userLogin">User Login Page</a><br>
	<a href="addUserPage">Add User Page</a><br>
	<a href="userList">User List Page</a><br>
	<a href="javascript:history.back()">Back</a>
</html>